package com.vben.system.biz.controller;

import com.vben.common.core.util.R;
import com.vben.system.api.entity.SysUserLoginLog;
import com.vben.system.biz.service.SysUserLoginLogService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 用户登陆日志控制层
 *
 * @author sunnfun
 */
@RestController
@RequestMapping("/loginLog")
public class SysUserLoginLogController {

    @Resource
    private SysUserLoginLogService sysUserLoginLogService;

    /**
     * 查询登陆日志信息
     *
     * @param loginId 登陆id
     * @return 登陆日志信息
     */
    @GetMapping("/info/loginId/{loginId}")
    public R<SysUserLoginLog> getByLoginId(@PathVariable("loginId") String loginId) {
        return R.ok(sysUserLoginLogService.getByLoginId(loginId));
    }

    /**
     * 新增登陆日志
     *
     * @param sysUserLoginLog 登陆日志信息
     * @return 新增结果
     */
    @PostMapping
    public R<Boolean> addLoginLog(@RequestBody SysUserLoginLog sysUserLoginLog) {
        return R.ok(sysUserLoginLogService.save(sysUserLoginLog));
    }

    /**
     * 修改日志登陆信息
     *
     * @param sysUserLoginLog 登陆日志信息
     * @return 更新结果
     */
    @PutMapping
    public R<Boolean> updateLoginLog(@RequestBody SysUserLoginLog sysUserLoginLog) {
        return R.ok(sysUserLoginLogService.updateById(sysUserLoginLog));
    }
}
